﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Hxsoft.AppV1.Module;

namespace Hxsoft.AppV1.Admin.ArticleManage
{
	public partial class Release : BasePage
	{
		/// <summary>
		/// 模块ID
		/// </summary>
		protected int ModuleID
		{
			get
			{
				return Convert.ToInt32(Request.QueryString["ModuleID"]);
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
				this.DataBind();
		}

		protected void Article1_SelectFinish(object sender, EventArgs e)
		{
			string message = BatchSelect(Article1.SelectedItems);
			Messages.Add(new PageMessage(true, null, PageMessageType.Prompt, Res.OperationCompleteTitle, message));
			LbSelectFinish.Visible = true;
		}

		protected string BatchSelect(List<int> items)
		{
			string message = "";

			foreach (int item in items)
			{
				ModuleArticleId identifier = new ModuleArticleId();
				identifier.ModuleId = ModuleID;
				identifier.ArticleId = item;

				if (ModuleArticles.GetReleaseRight(new ModuleArticle { ModuleId = identifier.ModuleId, ArticleId = identifier.ArticleId }))
				{
					if (ModuleArticles.Exists(identifier.ModuleId, identifier.ArticleId))
						message += "<li>栏目 [" + identifier.ModuleId + "] 已经存在文章 [" + identifier.ArticleId + "]。</li>";
					else
					{
						ModuleArticle info = new ModuleArticle();
						info.ModuleId = identifier.ModuleId;
						info.ArticleId = identifier.ArticleId;

						ModuleArticles.Release(info);
						message += "<li>向栏目 [" + identifier.ModuleId + "] 发布文章 [" + identifier.ArticleId + "] 成功。</li>";
					}
				}
				else
					message += "<li>您没有向栏目 [" + identifier.ModuleId + "] 发布文章  [" + identifier.ArticleId + "] 的权限。</li>";
			}

			return message;
		}
	}
}
